import { request } from './request'
import { formatDate } from '../utils/formatDate'
/*
 * 获取歌曲URL
 */
export const _getMuiscUrl = (id) =>
  request({
    url: '/song/url',
    params: {
      id
    }
  })

/*
 * 获取歌曲详情
 */
export const _getDetail = (id) =>
  request({
    url: '/song/detail',
    params: {
      id
    }
  })

/*
 * 音乐是否可用
 */
export const _musicCheck = (id) =>
  request({
    url: '/check/music',
    params: { id }
  })

/*
 * 获取歌词
 */
export const _getLyric = (id) =>
  request({
    url: '/lyric',
    params: { id }
  })

/*
 * 获取歌单详情
 */
export const _getMusicDetail = (id) =>
  request({
    url: '/playlist/detail',
    params: { id }
  })

/*
 * 获取歌单歌曲信息
 */
export const _getSongsDetail = (arr) =>
  request({
    url: '/song/detail',
    params: {
      ids: arr
    }
  })

/*
 * 获取收藏/取消收藏歌单
 *t : 类型,1:收藏,2:取消收藏 id : 歌单 id
 */
export const _getSubscribe = (t, id) =>
  request({
    url: '/playlist/subscribe',
    params: {
      t,
      id
    }
  })

/*
 * 获取歌单评论
 */
export const _getCommentRes = (id, limit, offset) =>
  request({
    url: '/comment/playlist',
    params: {
      id,
      limit,
      offset
    }
  })

/*
 * 获取歌单收藏者
 */
export const _getPlaylistSubscribes = (id, limit) =>
  request({
    url: '/playlist/subscribers',
    params: {
      id,
      limit
    }
  })

/*
 * 对歌单发表评论
 */
export const _getSubComment = (cookie, id, t, content, type, commentId) =>
  request({
    url: '/comment',
    params: {
      cookie,
      type,
      content,
      id,
      t,
      commentId
    }
  })

/*
 * 歌单详情信息
 */
export class BaseObj {
  constructor(playlist) {
    this.name = playlist.name
    this.coverImg = playlist.coverImgUrl || ''
    this.time = playlist.createTime
    this.tags = playlist.tags
    this.playCount = playlist.playCount
    this.shareCount = playlist.shareCount
    this.description = playlist.description
    this.trackCount = playlist.trackCount
    this.subscribedCount = playlist.subscribedCount
    this.creatorAvatar = playlist.creator.avatarUrl
    this.creatorName = playlist.creator.nickname
    this.subscribedId = playlist.subscribed
  }
}

/*
 * 对歌曲数据进行封装
 */
export class SongDetail {
  constructor(songs) {
    this.id = songs.id
    this.name = songs.name
    this.album = songs.al.name
    this.artist = songs.ar[0].name
    this.pic = songs.al.picUrl
    this.time = formatDate(new Date(songs.dt), 'mm:ss')
  }
}
